import java.util.StringTokenizer;

class ICPCP3281_7752 {

    public static void main(String[] args) {
    	int problemNumber = 1;
    	while (true) {
    		StringTokenizer st = new StringTokenizer(readLn());
    		int T = Integer.parseInt(st.nextToken());
    		int P = Integer.parseInt(st.nextToken());
    		
    		if (T == 0 && P ==0) break;
    		
    		System.out.println(problemNumber);
    		process(T, P);
    		problemNumber++;
    		
    		
    	}
    }

    private static void process(int T, int P) {
    	Team3281[] teams = new Team3281[T];
    	for (int k = 0; k < T; k++) {
    		teams[k] = new Team3281(k+1);
    	}
    	
		int[] problemsValues = new int[P];
		
		StringTokenizer st = new StringTokenizer(readLn());
		
		for (int k = 0; k < P; k++) {
			problemsValues[k] = Integer.parseInt(st.nextToken());
		}
		
		int S = Integer.parseInt(readLn());
		
		int teamNumber;
		int problem;
//		A, R
		
		for (int k = 0; k < S; k++) {
			st = new StringTokenizer(readLn());
			teamNumber = Integer.parseInt(st.nextToken());
			problem = problemsValues[(int)st.nextToken().charAt(0) - 'A'];
			Team3281 team = teams[teamNumber-1];
			team.submissions++;
			if ("A".equals(st.nextToken())) {
				team.correctSolutions++;
				team.points += problem;
			}
		}
		
//		for (Team3281 t : teams) {
//			System.out.println(t.getStats());
//		}
		
		sort(teams);
		
		for (int k = 0 ; k < T; k++)
			System.out.println(teams[k]);
	}

	private static void sort(Team3281[] teams) {
		
		for (int k = 0; k < teams.length - 1; k++) {
			for (int j = k + 1; j < teams.length; j++) {
				if (!betterThan(teams, k, j)) 
					swap(teams, k, j);
			}
		}
		
	}

	private static void swap(Team3281[] teams, int k, int j) {
		Team3281 aux = teams[k];
		teams[k] = teams[j];
		teams[j] = aux;
		
	}

//	The team with the most points wins. If teams are tied on points, 
//	the tie is broken in favour of the team with the fewer correct solutions. 
//	If teams are still tied, the tie is broken in favour of the team with the 
//	fewer total submissions. If teams are still tied, the tie is broken in 
//	favour of the team with the smaller team number.
	
	private static boolean betterThan(Team3281[] teams, int k, int j) {
		Team3281 a = teams[k];
		Team3281 b = teams[j];
		
		if (a.points > b.points) return true;
		if (a.points < b.points) return false;
		
		if (a.correctSolutions < b.correctSolutions) return true;
		if (a.correctSolutions > b.correctSolutions) return false;
		
		if (a.submissions < b.submissions) return true;
		if (a.submissions > b.submissions) return false;
		
		return a.number < b.number;
		
	}

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString()).trim();
    }

}

class Team3281 {

	int number;
	int points;
	int correctSolutions;
	int submissions;
	
	public Team3281(int number) {
		this.number = number;
	}

	public String getStats() {
		return "number: " + number + " points: " + points + " correct: " + correctSolutions + " submissions: " + submissions;
	}
 	
	public String toString() {
		return number + " " + points;
	}
}